<?php
/**
 * [PHPFOX_HEADER]
 */

defined('PHPFOX') or exit('NO DICE!');

/**
 * @author  		Miguel Espinoza (Purefan)
 */
class Iaip1_Service_Iaip1 extends Phpfox_Service 
{
	/**
	 * Class constructor
	 */	
	public function __construct()
	{	
		// no need to set anything here
	}
	
	
	public function fetchUsers($iDays)
	{
		// little validation
		
		if (!is_int($iDays) || ($iDays < 1))
		{
			return Phpfox_Error::set(Phpfox::getPhrase('iaip1.number_of_days'));
		}
		
		// $iDays ago was...
		$iAgo = PHPFOX_TIME - ($iDays * 60 * 60 * 24);
		// get the users
		$aUsers = $this->database()->select('user_id, user_name, email, last_login')
			->from(Phpfox::getT('user'))
			->where('last_login < ' . $iAgo)
			->execute('getSlaveRows');
		return $aUsers;
	}
	
	
	/**
	 * If a call is made to an unknown method attempt to connect
	 * it to a specific plug-in with the same name thus allowing 
	 * plug-in developers the ability to extend classes.
	 *
	 * @param string $sMethod is the name of the method
	 * @param array $aArguments is the array of arguments of being passed
	 */
	public function __call($sMethod, $aArguments)
	{				
		/**
		 * No method or plug-in found we must throw a error.
		 */
		Phpfox_Error::trigger('Call to undefined method ' . __CLASS__ . '::' . $sMethod . '()', E_USER_ERROR);
	}	
}

?>
